import getProp from './prop';
import { validateRequired } from '../rules/utils';

const TIPS_RADIO = '选择';
/**
 * 获取验证字段
 * @param {*} { fields }
 * @return {*} rule
 */
function _getRules({ fields }) {
  const { label, required } = getProp({ fields });
  const { verification } = fields;
  const { type } = verification;

  return {
    rules: [
      validateRequired(type, required, `请${TIPS_RADIO}${label}！`)
    ]
  };
}

/**
 * @export 获取radio类型表单属性
 * @param {*} { fields }
 * @return {*} prop
 */
export default function getRadioProp({ fields }) {
  const {
    choice,
    defaultProps
  } = fields;

  const prop = getProp({ fields });

  const rules = _getRules({ fields });

  return {
    ...prop,
    choice,
    defaultProps,
    ...rules
  };
}
